package org.example.Thread02;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;

public class Dome_Thread03 {
    public static void main(String[] args) throws InterruptedException {
        //创建一个ReentrantLock的对象
        ReentrantLock lock=new ReentrantLock();
        try {
            //加锁
            lock.lock();
            System.out.println("业务代码执行中...");
            TimeUnit.SECONDS.sleep(1);
            throw new InterruptedException("执行中出现异常...");
        } finally {
            //释放锁
            lock.unlock();
            System.out.println("锁已经释放...");
        }
    }
}
